#include <reg51.h>
#include "font.h"
#include "display1249.c"

#define STRING_LEN 4
unsigned char b[4],i=0,a;
sbit CS=P2^0;		// Chip Select of Display, We control Chip here so we can add multiple CS in main.c
/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Delay x Milisecond
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
void delay_ms(unsigned int x)	 // delays x msec (at fosc=11.0592MHz)
{
	unsigned char j=0;
	while(x-- > 0)
	{
		for (j=0; j<125; j++){;}
	}
}
void baud_init ()
	{	
		TMOD = 0x20;
		TH1 = 0xFD;
		SCON = 0x50;
		TR1 = 1;
	}

void rx()
{
			
      	while(i<4)
      	{
      	b[i]=SBUF;
      	i++;
      	}      	
      	
       	while(RI == 1);
		 	
	RI = 0;
}

void tx(unsigned char a)
{
      	SBUF = a;
		 	while(TI == 0);
			TI = 0;
}

void transmit()
{

	tx('A');
	tx('T');
	tx('+');
	tx('C');
	tx('M');
   tx('G');
	tx('F');
	tx('=');
	tx('1');
	tx('0x0d');
	tx('0x0a');
	delay_ms(100);
	tx('A');
	tx('T');
	tx('+');
	tx('C');
	tx('N');
   tx('M');
	tx('I');
	tx('=');
	tx('1');
	tx(',');
	tx('2');
   tx(',');
   tx('0');
   tx(',');
   tx('0');
   tx('0x0d');
	tx('0x0a');
   delay_ms(100);
}

void INI_1249(void)
{
   CS = 0;
   DIS_INIT_1249();         //inital 1632's set
   CS = 1;
   
   CS = 0;
   DIS_ALLRAM_1249(0);         //all LED write 0
   CS = 1;
   
}

void display(unsigned char adr, unsigned char dat)
{
   CS = 0;
   display_set(adr, dat);         //inital 1632's set
   CS = 1;		
}

void print_string()
{
	unsigned int font_pos;
	unsigned char char_pos, x, y;
	
		char_pos = 0;
	
		for(y=0; y<STRING_LEN; y++)
		{
			font_pos = (b[y] - ' ') * 5;
	
			for(x=0; x<5; x++)
			{
				display(char_pos++, font_5x7[font_pos+x]);				
			}	
delay_ms(500);
delay_ms(500);	
delay_ms(500);
delay_ms(500);
				char_pos++;	
		}
		
}
void main()
{
	baud_init ();
	INI_1249();
	
	print_string();
	
	while(1)
	{
	
	}
}


 